package cn.helios._03_rocketMQ;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * @BelongsProject: rocketmq-test
 * @BelongsPackage: cn.itsource._03_delay
 * @Author: 笔上人间
 * @CreateTime: 2022-7-23 21:01:39
 * @Description: 消息生产者
 * @Version: 1.0
 */
public class Producer {

    public static void main(String[] args) throws Exception {
        // 1.创建消费者对象
        DefaultMQProducer producer = new DefaultMQProducer("he_producer_group");
        // 2.连接mq
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 3.启动消费者
        producer.start();
        // 4.发送延迟消息
        Message message = new Message("he_topic3", "he_tags3", "我再源码学习开车！".getBytes(StandardCharsets.UTF_8));
        // 4.1.设置延迟消息级别
        message.setDelayTimeLevel(3);
        SendResult sendResult = producer.send(message);
        System.out.println(sendResult);
        // 5.关闭消费者
        producer.shutdown();
    }
}